//
//  MPStatusViewModel.swift
//  MPSinaWeibo
//
//  Created by DaVinci on 16/4/13.
//  Copyright © 2016年 DaVinci. All rights reserved.
//

import UIKit

class MPStatusViewModel: NSObject {

    //在初始化方法，或者didSet内部给status赋值 不会调用didSet
    var status: MPStatus?
    //模型中 mbrank不能直接用于视图显示 需要进行额外的处理
    var mbImage: UIImage?
    
    //认证类型的图片
    var verifiedImage: UIImage?
    
    var headImageURL: NSURL?
    
    init(status: MPStatus) {
        
        super.init()
       
        //记录参数
        self.status = status
        
        headImageURL = NSURL(string: status.user?.profile_image_url ?? "")

        //直接计算
        //用户等级
         dealmbRank()
        
        
        //用户的认证类型
        //用户认证类型
        dealVerifiedType()
        
    }

    
}

//处理微博数据
extension MPStatusViewModel {
    private func dealmbRank() {
        let mbType = status?.user?.mbrank ?? 0
        if mbType > 0 && mbType < 7 {
            mbImage = UIImage(named: "common_icon_membership_level\(mbType)")
        }
    }
    
    private func dealVerifiedType() {
        //用户认证类型
        let verifiedType = status?.user?.verified ?? -1
        switch verifiedType {
        case 1:
            verifiedImage = UIImage(named: "avatar_vip")
        case 2,3,5:
            verifiedImage = UIImage(named: "avatar_enterprise_vip")
        case 220:
            verifiedImage = UIImage(named: "avatar_grassroot")
        default:
            verifiedImage = nil
        }
        
    }
}

